import grails.util.GrailsUtil

class BootStrap {

    def init = {servletContext ->

        createBlogConfig()
        
        if (GrailsUtil.environment == "development") {
            Tag java = new Tag(name: "java")

            new Post(title: "First Grails Project",
                    teaser: "Clearing out the clutter",
                    content: """The full content of the article

paragraph one
second paragraph""",
                    published: true).addToTags(java).save()


            new Post(title: "Getting Ready for Go Live",
                    teaser: "The follow up on some real world issues.",
                    content: "The full content of the article",
                    published: false).addToTags(java).addToTags(new Tag(name: "latest")).save()

            new User(username: "jon",
                    password: "password",
                    firstName: "Jon",
                    lastName: "Dickinson").save()
        }

    }

    def destroy = {
    }

    def createBlogConfig() {
        def configs = BlogConfig.list()
         if(configs?.size() == 0) {
             BlogConfig config = new BlogConfig(title:"Jon Dickinson's Blog", description:"On software development")
             config.save()         
         }
    }
} 